﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
    <link href="/lib/jquery/jquery-ui.min.css" rel="stylesheet" />
    <script src="/lib/jquery/jquery-ui.min.js"></script>
</head>
<body>
    <section class="container-fluid" style="background-color: white;">
        <form class="form-horizontal m15_t" id="form">
            <div class="tab-content">

                <input type="hidden" name="configId" value="0">

                <div class="tab-pane fade in active" id="divSysConfig">
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span> 分类代码：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="configCode" maxlength="40" autocomplete="off" placeholder="分类代码长度必须介于 1 和 40 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span> 分类值：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="configValue" maxlength="20" autocomplete="off" placeholder="分类值只能为整数">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"> 分类名称：</label>
                        <div class="wd250 m15_l">
                            <textarea style="height: auto;font-size: 12px;width: 100%;" type="text" name="configContent" maxlength="200"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>公司名称：</label>
                        <select class="m15_l" name="companyId" id="companyId"></select>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label">分类说明：</label>
                        <div class="wd250 m15_l">
                            <textarea style="height: auto;font-size: 12px;width: 100%;" type="text" name="description" maxlength="200"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </section>
    <script type="text/javascript">
        var validator = null;

        var companyId = $("select[name='companyId']");

        var configId = 0;

        $(function () {

            configId = FlashPay.Util.GetQueryString("configId");

            init(configId);

        });

        function init(configId) {

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            var requestUrl = configId > 0 ? "/SysConfig/GetEdit?configId=" + configId : "/SysConfig/GetAdd?configId=" + configId;

            //获取参数信息
            FlashPay.Util.Ajax({
                type: "POST",
                url: requestUrl,
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    if (res.success) {
                        
                        FlashPay.Util.SetInputVal("configId", res.data.configId);
                        FlashPay.Util.SetInputVal("configCode", res.data.configCode);
                        FlashPay.Util.SetInputVal("configValue", res.data.configValue > 0 ? res.data.configValue:"");
                        $("textarea[name='configContent']").val(res.data.configContent);
                        $("textarea[name='description']").val(res.data.description);
                        
                        companyId.append("<option value=''>请选择</option>");
                        if (res.data.companyResponse != null) {
                            $.each(res.data.companyResponse, function (i, item) {
                                companyId.append("<option value='" + item.companyID + "'>" + item.companyName + "</option >");
                            });
                            $("select[name='companyId']").find("option[value=" + res.data.companyId + "]").prop("selected", true);
                        }

                        cover.Remove();
                    }
                },
                error: function (json) {
                    cover.Remove();
                }
            });
        }

        function save() {

            var sysConfig = {};
            sysConfig.configId = $("input[name='configId']").val();
            sysConfig.configCode = $("input[name='configCode']").val();
            sysConfig.configValue = $("input[name='configValue']").val();
            sysConfig.companyId = $("select[name='companyId']").find("option:selected").val();
            sysConfig.configContent = $.trim($("textarea[name='configContent']").val());
            sysConfig.description = $.trim($("textarea[name='description']").val());

            FlashPay.Util.Ajax({
                url: '/SysConfig/SysConfigAddOrEdit',
                type: 'POST',
                data: sysConfig,
                dataType: 'json',
                success: function (res) {
                    if (res.success) {
                        FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    } else {
                        FlashPay.UI.Tip_short_warning("操作失败," + res.errorMessage);
                    }
                },
                error: function (json) {
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试。");
                }
            });
        }
    </script>
</body>
</html>